package pe.edu.pucp.dp1.principal;

import Shared.ListObjCarZona;
import Shared.MatrizInterseccionSalida;
import Shared.ServMain;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import javax.swing.UIManager;
import pe.edu.pucp.dp1.gui.vista.Login;
import pe.edu.pucp.dp1.lectura.controlador.GestorCar;
import pe.edu.pucp.dp1.procesamiento.controlador.GestorInterseccion;

public class ServMainImpl extends UnicastRemoteObject implements ServMain {

    ServMainImpl() throws java.rmi.RemoteException {
        super();
    }

    //PROCESAMIENTO
    public static GestorInterseccion gestorInter = GestorInterseccion.getInstance();

    public boolean iniProcesamiento() {
        gestorInter.iniSimIntersecciones();
        return true;
    }

    public int getNumZonasLargo() {
        return gestorInter.getnZonasLargo();
    }

    public int getNumZonasAlto() {
        return gestorInter.getnZonasAlto();
    }

    public MatrizInterseccionSalida obtInterPorCoord(int xCoord, int yCoord) {
        return gestorInter.obtInterPorCoord(xCoord, yCoord);
    }

    public boolean iniHiloGenetico() {
        return gestorInter.iniHiloGenetico();
    }

    public boolean agregarSemaforo(int xCoord, int yCoord) {
        return gestorInter.agregarSemaforo(xCoord, yCoord);
    }

    public boolean eliminarSemaforo(int xCoord, int yCoord) {
        return gestorInter.eliminarSemaforo(xCoord, yCoord);
    }

    //LECTURA
    public static GestorCar gestorCar = GestorCar.getInstance();

    public void iniciaLectura() {
        gestorCar.iniLectura();
    }

    public double getVelocidadPromedio() {
        return gestorCar.velocidadPromedio();
    }

    public ListObjCarZona getlistCarrosPorZona(int x, int y) {
        return gestorCar.listCarrosPorZona(x, y);
    }

    public ArrayList<ListObjCarZona> getlistCarrosTotal() {
        return gestorCar.listCarrosTotal();
    }

    public static void main(String args[]) {

        System.setProperty("java.security.policy", "D:\\javafiles\\javapolicy\\java.policy");
        //System.setProperty("java.security.policy", "/home/javier/Escritorio/DP/javapolicy/java.policy");

        //System.setProperty("java.rmi.server.hostname", "192.168.1.213");
        try {
            ServMainImpl ServMain;
            LocateRegistry.createRegistry(1099);
            ServMain = new ServMainImpl();
            Naming.bind("ServMain", ServMain);
            System.out.println("El servidor esta listo\n");

            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                System.out.println("No se puede cambiar el LF");
            }
            Login login = new Login();
            login.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
